package com.ludum.game.rendering;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Matrix4;
import com.ludum.game.player.Player;

public class Camera2D {	
	public OrthographicCamera  cam;
	private Player player1;
	private Player player2;
	
	
	public Camera2D(Player p1, Player p2) {
		float height = Gdx.graphics.getHeight();
		float width = Gdx.graphics.getWidth();
		cam = new OrthographicCamera(width, height);
		cam.position.set(width/2.f, height/2.f, 0);
		player1 = p1;
		player2 = p2;
	}
	
	
	/**
	 * update camera position to the mean of the two player x coordinates
	 * @param p1 the first player
	 * @param p2 the second player
	 */
	public void update() {
		cam.position.x = (player1.getPosition().x +  player2.getPosition().x)/2.f;
		cam.update();
	}
	
	
	/**
	 * Get the camera projection matrix
	 * @return the projection matrix
	 */
	public Matrix4 getProj() {
		return cam.combined;
	}
}
